package com.leexuan.ordersystem.actions;

import java.util.ArrayList;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.leexuan.ordersystem.beans.Customer;
import com.leexuan.ordersystem.beans.Order;
import com.leexuan.ordersystem.db.CustomerDB;
import com.leexuan.ordersystem.db.DeliverDB;
import com.leexuan.ordersystem.db.OrderDB;

public class ListDeliverDetailAction extends Action {

	public ListDeliverDetailAction() {
		super();
	}

	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) throws Exception {

		int oid = Integer.parseInt(request.getParameter("oid"));

		HttpSession session = request.getSession();

		try {

			OrderDB db = new OrderDB();
			db.getConnection();
			Order order = db.getOrder(oid);

			CustomerDB cdb = new CustomerDB();
			Customer customer = null;
			cdb.getConnection();
			customer = cdb.getCustomer(order.getCid());

			DeliverDB ddb = new DeliverDB();
			ArrayList deliverdetail = null;
			ddb.getConnection();
			deliverdetail = ddb.getDeliverDetails(oid);

			session.setAttribute("order", order);
			session.setAttribute("customer", customer);
			session.setAttribute("deliverdetail", deliverdetail);

			return mapping.findForward("success");

		} catch (Exception e) {

			return (new ActionForward(mapping.getInput()));
		} finally {
			try {

			} catch (Exception e) {
				e.printStackTrace();
			}
		}

	}

}
